package com.lemon.blog.web.service.impl;

import java.util.List;

import com.lemon.common.core.exception.ServiceException;
import com.lemon.common.security.utils.SecurityUtils;
import org.springframework.beans.factory.annotation.Autowired;
import org.springframework.stereotype.Service;
import com.lemon.common.security.utils.OptEntityUtils;
import com.lemon.common.security.service.BaseServiceImpl;
import com.lemon.blog.web.mapper.BiUserFollowMapper;
import com.lemon.blog.web.domain.BiUserFollow;
import com.lemon.blog.web.service.IBiUserFollowService;

/**
 * 包名称：com.lemon.blog.web.service.impl
 * 类名称：BiUserFollowServiceImpl
 * 类描述：用户关注表Service业务层处理
 * 创建人：@author lemon
 * 创建时间：2023-10-10
 */
@Service
public class BiUserFollowServiceImpl extends BaseServiceImpl<BiUserFollow> implements IBiUserFollowService {

    @Autowired
    private BiUserFollowMapper biUserFollowMapper;

    @Override
    public int insert(BiUserFollow model) {
        biUserFollowMapper.deleteByUserIdAndFollowUserId(SecurityUtils.getWebUserId(), model.getFollowUserId());
        model.setUserId(SecurityUtils.getWebUserId());
        OptEntityUtils.preInsert(model);
        return biUserFollowMapper.insertSelective(model);
    }

    @Override
    public List<BiUserFollow> selectBiUserFollowList(BiUserFollow biUserFollow) {
        return biUserFollowMapper.selectBiUserFollowList(biUserFollow);
    }

    @Override
    public boolean deleteFollow(Long followUserId) {
        int count = biUserFollowMapper.deleteByUserIdAndFollowUserId(SecurityUtils.getWebUserId(), followUserId);
        if (count < 1) {
            throw new ServiceException("您还没有关注当前用户");
        }
        return true;
    }
}
